home *** CD-ROM | disk | FTP | other *** search
/ Aminet 28 / Aminet 28 (1998)(GTI - Schatztruhe)[!][Dec 1998].iso / Aminet / dev / misc / gms_pictures.lha / Pictures / pictures.c < prev    next >
Encoding:
C/C++ Source or Header  |  1998-10-14  |  8.4 KB  |  231 lines

  1. /*
  2. ** Module:    Pictures.
  3. ** Author:    Paul Manias
  4. ** Copyright: DreamWorld Productions (c) 1996-1998.  All rights reserved.
  5. **
  6. ** --------------------------------------------------------------------------
  7. ** 
  8. ** TERMS AND CONDITIONS
  9. ** 
  10. ** This source code is made available on the condition that it is only used to
  11. ** further enhance the Games Master System.  IT IS NOT DISTRIBUTED FOR THE USE
  12. ** IN OTHER PRODUCTS.  Developers may edit and re-release this source code
  13. ** only in the form of its GMS module.  Use of this code outside of the module
  14. ** is not permitted under any circumstances.
  15. ** 
  16. ** This source code stays the copyright of DreamWorld Productions regardless
  17. ** of what changes or additions are made to it by 3rd parties.  A joint
  18. ** copyright can be granted if the 3rd party wishes to retain some ownership
  19. ** of said modifications.
  20. ** 
  21. ** In exchange for our distribution of this source code, we also ask you to
  22. ** distribute the source when releasing a modified version of this module.
  23. ** This is not compulsory if any additions are sensitive to 3rd party
  24. ** copyrights, or if it would damage any commercial product(s).
  25. ** 
  26. ** --------------------------------------------------------------------------
  27. **
  28. ** BUGS AND MISSING FEATURES
  29. ** -------------------------
  30. ** If you correct a bug or fill in a missing feature, the source should be
  31. ** e-mailed to pmanias@ihug.co.nz for inclusion in the next update of this
  32. ** module.
  33. **
  34. ** If you want to add support for picture files like BMP, PCX, JPG
  35. ** or GIF then you need to create a child module such as "pictures_pcx.mod".
  36. ** This involves cloning this module and then making some modifications
  37. ** to the AddSysObject() part, plus creating a suitable reference file (see
  38. ** GMSDev:Source/References/pictures.ref for an example).  You can remove
  39. ** support for almost all the actions, but must write code for Init(),
  40. ** CheckFile() and Query().  If you want to save pictures in the file format,
  41. ** write code for SaveToFile() as well.
  42. **
  43. ** This isn't too hard so long as you have *read the autodocs*.  For any
  44. ** quesions or help in doing this, send me an e-mail.
  45. **
  46. ** CHANGES
  47. ** -------
  48. ** -1997-
  49. ** 13 Jul Removed the UnpackPic() function from public use.
  50. ** 29 Jul Removed GetPicInfo(), replaced with Query().
  51. **        We are no longer remapping the kernel (100% object oriented).
  52. ** 03 Aug Moved module over to C.
  53. **        Converted CopyToUnv(), CopyFromUnv().
  54. ** 17 Sep Moved Write(), Read(), Load() and CheckFile() over to C.
  55. **        Moved SetPicViewMode(), SetPicColours(), SetPicPlanes(),
  56. **         SetPicDimensions(), Query(), Init() over to C.
  57. ** 03 Oct Updated more parts to C code.
  58. **        Created C version of IFF chunk searching routine.
  59. **
  60. ** -1998-
  61. ** 08 Jan Removed Palette field, now inherited from Bitmap.
  62. **        No longer interfering with palettes.
  63. ** 29 Jan Load(Picture) no longer stores the data in video memory.
  64. ** 03 May Totally re-wrote the picture unpacking, resizing and remapping.
  65. ** 31 May Added field orientation support.
  66. ** 21 Jun Added support for loading a picture in chunks, and body data is
  67. **        now loaded in sets of 8kb rather than trying to read it all at once.
  68. **        Module is now compiled with neardata option for SAS/C.
  69. ** 04 Jul Fixed bug in SkipLine(), it was not skipping all the bitplanes.
  70. ** 20 Aug Query() now queries the Picture->Bitmap instead of initialising it.
  71. ** 01 Sep Added faster pixel processing by using the Bitmap's internal pixel
  72. **         functions (e.g. Bitmap->DrawPixel()).
  73. ** 03 Sep Picture->Init() will now initialise the child Bitmap instead of
  74. **        only querying it.
  75. */
  76.  
  77. #include <proto/dpkernel.h>
  78. #include <system/all.h>
  79. #include <dpkernel/prefs.h>
  80. #include "defs.h"
  81.  
  82. /**********************************************************************************/
  83.  
  84. BYTE ModAuthor[]    = "Paul Manias";
  85. BYTE ModDate[]      = "October 1998";
  86. BYTE ModCopyright[] = "DreamWorld Productions (c) 1996-1998.  All rights reserved.";
  87. BYTE ModName[]      = "Pictures";
  88.  
  89. /***********************************************************************************
  90. ** Picture Definition
  91. */
  92.  
  93. struct FieldDef OptionFlags[] = {
  94.   { "RESIZEX", 0x00000001 }, { "REMAP", 0x00000004 }, { "RESIZEY", 0x00000008 },
  95.   { NULL, NULL }
  96. };
  97.  
  98. struct FieldDef ScrFlags[] = {
  99.   { "HIRES", 0x00000001 }, { "SHIRES", 0x00000002 }, { "LACED", 0x00000004 },
  100.   { "LORES", 0x00000008 }, { "SLACED", 0x00000010 },
  101.   { NULL, NULL }
  102. };
  103.  
  104. #define PIC_FIELDS 6
  105.  
  106. struct Field PictureFields[PIC_FIELDS] = {
  107.   { "Bitmap",    12, FID_Bitmap,    FDF_CHILD,          ID_BITMAP, 0,          NULL, NULL },
  108.   { "Options",   16, FID_Flags,     FDF_LONG|FDF_FLAGS, (LONG)&OptionFlags, 0, NULL, NULL },
  109.   { "Source",    20, FID_Source,    FDF_SOURCE,         0, 0,                  NULL, NULL },
  110.   { "ScrMode",   24, FID_ScrMode,   FDF_WORD|FDF_FLAGS, (LONG)&ScrFlags, 0,    NULL, NULL }, 
  111.   { "ScrHeight", 26, FID_ScrHeight, FDF_WORD|FDF_RANGE, 0, 2560,               NULL, NULL },
  112.   { "ScrWidth",  28, FID_ScrWidth,  FDF_WORD|FDF_RANGE, 0, 2560,               NULL, NULL },
  113. };
  114.  
  115. /***********************************************************************************
  116. ** Command: Init()
  117. ** Short:   Called when our module has been loaded for the first time.  Any
  118. **          allocations made here will need to be freed in the FreeModule()
  119. **          function.
  120. */
  121.  
  122. LIBFUNC LONG CMDInit(mreg(__a0) LONG argModule,
  123.                      mreg(__a1) LONG argDPKBase,
  124.                      mreg(__a2) LONG argGVBase,
  125.                      mreg(__d0) LONG argDPKVersion,
  126.                      mreg(__d1) LONG argDPKRevision)
  127. {
  128.   DPKBase = (APTR)argDPKBase;
  129.   GVBase  = (struct GVBase *)argGVBase;
  130.   Public  = ((struct Module *)argModule)->Public;
  131.  
  132.   if ((argDPKVersion < DPKVersion) OR
  133.      ((argDPKVersion IS DPKVersion) AND (argDPKRevision < DPKRevision))) {
  134.      DPrintF("!Pictures:","This module requires V%d.%d of the dpkernel.library.",DPKVersion,DPKRevision);
  135.      return(ERR_FAILED);
  136.   }
  137.  
  138.   if (!(PicObject = AddSysObjectTags(ID_PICTURE, ID_PICTURE, "Picture",
  139.         TAGS, NULL,
  140.         SOA_FileExtension, "iff;ilbm;pic",
  141.         SOA_FileDesc,      "IFF Picture",
  142.         SOA_CheckFile,     PIC_CheckFile,
  143.         SOA_CopyToUnv,     PIC_CopyToUnv,
  144.         SOA_CopyFromUnv,   PIC_CopyFromUnv,
  145.         SOA_Free,          PIC_Free,
  146.         SOA_Get,           PIC_Get,
  147.         SOA_Init,          PIC_Init,
  148.         SOA_Load,          PIC_Load,
  149.         SOA_Query,         PIC_Query,
  150.         SOA_Read,          PIC_Read,
  151.         SOA_SaveToFile,    PIC_SaveToFile,
  152.         SOA_Seek,          PIC_Seek,
  153.         SOA_Write,         PIC_Write,
  154.         SOA_FieldArray,    PictureFields,
  155.         SOA_FieldTotal,    PIC_FIELDS,
  156.         SOA_FieldSize,     sizeof(struct Field),
  157.         SOA_ObjectSize,    sizeof(struct Picture),
  158.         SOA_ClassVersion,  VER_PICTURE
  159.         TAGEND))) {
  160.      FreeModule();
  161.      return(ERR_FAILED);
  162.   }
  163.  
  164.   return(ERR_OK);
  165. }
  166.  
  167. /***********************************************************************************
  168. ** Command: Open()
  169. ** Short:   Called when our module is being opened (from an Init(Module)).
  170. */
  171.  
  172. LIBFUNC LONG CMDOpen(mreg(__a0) struct Module *Module)
  173. {
  174.   Module->FunctionList = NULL;
  175.   Public->OpenCount++;
  176.   return(ERR_OK);
  177. }
  178.  
  179. /***********************************************************************************
  180. ** Command:  Expunge()
  181. ** Synopsis: LONG Expunge(void);
  182. ** Short:    Called on expunge - if no program has us opened then we can give
  183. **           permission to have us shut down.
  184. */
  185.  
  186. LIBFUNC LONG CMDExpunge(void)
  187. {
  188.   if (Public) {
  189.      if (Public->OpenCount IS NULL) {
  190.         FreeModule();
  191.         return(ERR_OK); /* Okay to expunge */
  192.      }
  193.   }
  194.   else DPrintF("!Pictures:","I have no Public base reference.");
  195.  
  196.   return(ERR_FAILED); /* Do not expunge */
  197. }
  198.  
  199. /***********************************************************************************
  200. ** Command:  Close()
  201. ** Synopsis: void Close(*Module [a0]);
  202. ** Short:    Called whenever someone is closing a link to our module.
  203. */
  204.  
  205. LIBFUNC void CMDClose(mreg(__a0) struct Module *Module)
  206. {
  207.   if (Public) Public->OpenCount--;
  208. }
  209.  
  210. /***********************************************************************************
  211. ** Internal: FreeModule()
  212. **
  213. ** Frees any allocations made in the opening of our module.
  214. */
  215.  
  216. void FreeModule(void)
  217. {
  218.   if (PicObject) RemSysObject(PicObject);
  219. }
  220.  
  221. /***********************************************************************************
  222. ** Action: SaveToFile()
  223. ** Object: Picture
  224. */
  225.  
  226. LIBFUNC LONG PIC_SaveToFile(mreg(__a0) struct Picture *Picture, mreg(__a1) struct File *File)
  227. {
  228.   return(SaveToFile(Picture->Bitmap,(APTR)File,NULL));
  229. }
  230.  
  231.